<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
	<title>底部菜单</title>
	<link rel="stylesheet" href="../css/iconfont/iconfont.css" />
	<link rel="stylesheet" href="../script/swiper/swiper.min.css">
	<link rel="stylesheet" type="text/css" href="../css/aui2.1/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui2.1/aui-slide.css" />
	<link rel="stylesheet" type="text/css" href="../css/reset_lituo.css" />
	<style type="text/css">
		body{background:#f5f5f5;}
		img{width:100%;height:auto;}
		/* icon/start */
		.iconfont{width:2rem;height:2rem;text-align:center;line-height:2rem;display:inline-block;color:#fff;border-radius:50%;}
		/* icon/end */
		.wenzi span{position:absolute;z-index:9;top:2.6rem;color:#fff;font-size:0.8rem;font-weight:bold;letter-spacing:0.2rem;;left:3.6rem;}
		footer .iconfont{color:#1c1c1c;font-size:1rem;}
		.aui-bar-tab .aui-active{color:#e0483e;}

		img{width:100%;height:auto;}

		.aui-grid .aui-grid-label{font-size:0.6rem;}

		.iconfont1{ height: 0rem;}
		.aui-searchbar{width: 80%;background-color: rgba(0,0,0,0);margin-left: 15%;}
		.aui-searchbar-input{border-radius: 1.25rem;}
		.aui-icon-search{font-size: 0.8rem !important;}
		.aui-searchbar-input{padding-top: 3px;}
		.logos{width: 80px;height: 20px;}
	</style>
</head>
<body>
<header class="aui-bar aui-bar-nav" id="header">我的</header>

<footer class="aui-bar aui-bar-tab" id="footer">
	<div class="aui-bar-tab-item aui-active" tapmode onclick="clickMenu(this,'0')">
		<i class="iconfont icon-- aui-active iconfont1" id="footer1"></i>
		<div class="aui-bar-tab-label">首页</div>
	</div>
	<div class="aui-bar-tab-item" id="middleBtnF">
		<i class="iconfont icon--1 iconfont1"></i>
		<div class="aui-bar-tab-label" id="middleBtn">咨询</div>
	</div>
	<div class="aui-bar-tab-item" tapmode onclick="clickMenu(this,'1')">
		<i class="iconfont icon-icon-test2 iconfont1" id="footer2"></i>
		<div class="aui-bar-tab-label">我的</div>
	</div>
</footer>
</body>
</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/swiper/swiper.min.js"></script>
<script type="text/javascript" src="../script/aui/aui-slide.js"></script>
<script type="text/javascript" src="../script/common/common.js"></script>
<script type="text/javascript" src="../script/common/check.js"></script>
<script type="text/javascript" src="../script/common/config.js"></script>
<script type="text/javascript">
	apiready = function(){
		fnTuiChu();
		//接收来自my-index.html 发送的userInfoUpdatas监听事件 更改底部中间按钮
		var parameter = {name:'userInfoUpdatas'};
		get_addEventListener(parameter,function(){
			//判断用户角色--显示中间按钮
			var userInfo = $api.getStorage('user');
			var jobClass = userInfo.job_class;

			if (jobClass == 0) {
				$api.text($api.byId('middleBtn'), '咨询');
				$api.addEvt($api.byId('middleBtnF'), 'click', secondSheet);
			} else {
				$api.html($api.byId('middleBtnF'), '<i class="iconfont icon--1 iconfont1"></i><div class="aui-badge" id="aui-badge" style="display:none;"></div><div class="aui-bar-tab-label" id="middleBtn">咨询记录</div>');
				$api.addEvt($api.byId('middleBtnF'), 'click', searchRecord);
			}
		})
		api.parseTapmode();


		// 监听未读消息
		api.addEventListener({
			name: 'UnreadMessageAmount'
		}, function(ret, err){
			if( ret ){
				if(ret.value.amount == '0'){
					$api.css($api.byId('aui-badge'), 'display:none;');
				}else{
					var badgeNumber = $api.byId('aui-badge');
					$api.css(badgeNumber, 'display:block;');
					$api.text(badgeNumber, ret.value.amount);
				}
			}
		});

		// home_index();
		api.setFrameGroupIndex({
			name: 'footer_tab',
			index: 0
		});


		//设置Grop组
		var header = $api.byId('header');
		$api.fixStatusBar(header);
		var headerPos = $api.offset(header),
			frameheight = api.winHeight - $api.byId('footer').offsetHeight - $api.byId('header').offsetHeight;
		api.openFrameGroup ({
			name: 'footer_tab',
			scrollEnabled: false,
			rect: {
				x: 0,
				y: headerPos.h,
				w: 'auto',
				h: frameheight
			},
			index: 0,
			frames: [{
				name: 'home',
				url: './home/index.html',
				bounces : false
			},{
				name: 'my',
				url: './my/index.html',
				bounces : false,
				scrollEnabled: false
			}]
		}, function(ret, err){
			if(ret){
				var index = ret.index;
				switch(index){
					case 0:
						api.parseTapmode();
						$api.html($api.byId('header'), '<div class="aui-searchbar" id="search"><div class="aui-searchbar-input aui-border-radius" tapmode onclick="doSearch()"><i class="aui-iconfont aui-icon-search"></i><input type="search" placeholder="请输入搜索内容" id="search-input"></div><span><img src="../image/logo_s.png" class="logos"/></span></div>');
						break;
					case 1:
						api.parseTapmode();
						$api.text($api.byId('header'), '我的');
						break;
				}
			}else{
				alert( JSON.stringify( err ) );
			}
		});
	}

	//底部菜单点击
	function clickMenu(obj,location){
		if (location == '0') {
			$api.removeCls($api.byId('footer1'), 'icon-icon-test');
			$api.addCls($api.byId('footer1'), 'icon--');
			$api.addCls($api.byId('footer2'), 'icon-icon-test2');
			$api.removeCls($api.byId('footer2'), 'icon--2');
		}
		if (location == '1') {
			$api.removeCls($api.byId('footer2'), 'icon-icon-test2');
			$api.addCls($api.byId('footer2'), 'icon--2');
			$api.addCls($api.byId('footer1'), 'icon-icon-test');
			$api.removeCls($api.byId('footer1'), 'icon--');
		}
		var footerButton = $api.byId('footer') ,
			selectButton = $api.dom(footerButton, '.aui-bar-tab div.aui-active');
		$api.removeCls(selectButton, 'aui-active');
		$api.removeCls($api.first(selectButton,'i'), 'aui-active');
		$api.addCls(obj, 'aui-active');
		$api.addCls($api.first(obj,'i'), 'aui-active');
		switch(location){
			case '0':
				api.setFrameGroupIndex({
					name: 'footer_tab',
					index: 0
				});
				break;
			case '1':
				api.setFrameGroupIndex({
					name: 'footer_tab',
					index: 1,
					reload: true
				});
				break;
		}
	}

	//点击中间按钮--咨询
	function secondSheet(){
		var name = 'secondSheet',
			url =  './consult/secondSheet.html';
		open_w(name,url);
	}

	//点击中间按钮--咨询记录
	function searchRecord(){
		var name = 'searchRecord',
			url =  './consult/message_win.html';
		open_w(name,url);
	}


	/*搜索*/
	function doSearch(){
		var name = 'search_win',
			url =  './search/search_win.html';
		open_w(name,url);
	}
	/*监听安卓手机点击返回按钮*/
	function fnTuiChu(){
		api.addEventListener({
			name: 'keyback'
		},function(ret,err){
			api.toast({
				msg: '再按一次退出' + api.appName,
				duration: 2000,
				location: 'bottom'
			});
			api.addEventListener({
				name: 'keyback'
			}, function(ret, err) {
				api.closeWidget({
					silent: true
				});
			});
		});
	}
</script>